<html>
    <head>
        {% include 'link_css.html' %}
        {% include 'head_script.html' %}
        <style>
            body {background: #ffffff;}
        </style>
    </head>
{% load mytags %}
{% load bootstrap %}
{% block content %}
{# {% include 'nav_cat_bar.html' %}#}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-10">
            <div class="ibox float-e-margins">
                {# <div id="ibox-content" class="ibox-title">#}
                    <h5> 资产基本信息 </h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                {# </div>#}

                <div class="ibox-content">
                    <div class="panel blank-panel">
                        {% comment %}

                        <div class="panel-options">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="{% url 'asset_add' %}" class="text-center"><i class="fa fa-laptop"></i> 单条修改 </a></li>
                                <li><a href="{% url 'asset_add_batch' %}" class="text-center"><i class="fa fa-bar-chart-o"></i> 批量添加 </a></li>
                            </ul>
                        </div>
                        {% endcomment %}
                        <div class="panel-body">
                            <div class="tab-content">
                                    <form id="assetForm" method="post" class="form-horizontal">
                                        {% csrf_token %}
                                        <div class="form-group col-sm-13 col-lg-13" >
                                            <div class="col-sm-5 col-lg-5">
                                               <select id="keyfield" name="keyfield" class="form-control m-b input-sm" >
                                                           <option value="">过滤字段</option>
                                                           {% for field in model_fields  %}
                                                               <option value="{{ field }}"> {{ model_fields|get_dict_value:field|slice:":20" }}</option>
                                                           {% endfor %}
                                               </select>
                                           </div>
                                            <div class="form-group input-group inline-group col-sm-7 col-lg-7" >
                                               <input type="text" class="form-control m-b input-sm" id="keyword" name="keyword" value="{{ keyword }}" placeholder="过滤条件.">
                                            </div>
                                        </div>

                                <div id="tab-1" class="ibox float-e-margins tab-pane active">
                                    {% if error %}
                                        <div class="alert alert-danger text-center">{{ error }}</div>
                                    {% endif %}
                                    {% if msg %}
                                        <div class="alert alert-success text-center">{{ msg }}</div>
                                    {% endif %}

                                    <div class="col-sm-12 col-lg-12">
                                        <div class="alert alert-danger"><b>注意！所有符合条件的资产都会被修改.不填写条件则默认所有.请小心使用.!!!!</b></div>
                                    </div>
                                    <div class="hr-line-dashed"></div>

                                        {# {{ af.it_serial | bootstrap_horizontal }}#}
                                        {# <div class="hr-line-dashed"></div>#}
                                        {{ af.it_status|bootstrap_horizontal }}
                                        <div class="hr-line-dashed"></div>
                                        {{ af.it_type|bootstrap_horizontal }}
                                        <div class="form-group" id="new_it_type" style="display:none">
                                            <label class="control-label col-sm-2 col-lg-2 red-fonts">新增类型名</label>
                                            <div class=" col-sm-10 col-lg-10 ">
                                                <input class=" form-control" maxlength="32" name="new_it_type" type="text" >
                                                <button type="button" class="col-sm-2 btn btn-info" id="new_field">添加</button>
                                            </div>
                                        </div>

                                        <div class="hr-line-dashed"></div>
                                        {{ af.it_reason|bootstrap_horizontal }}
                                        <div class="hr-line-dashed"></div>
                                        {{ af.it_dep|bootstrap_horizontal }}
                                        <div class="form-group" id="new_it_dep" style="display:none">
                                            <label class="control-label col-sm-2 col-lg-2 red-fonts">新增部门名</label>
                                            <div class=" col-sm-10 col-lg-10 ">
                                                <input class=" form-control" maxlength="32" name="new_id_dep" type="text">
                                                <button type="button" class="col-sm-2 btn btn-info" id="new_field">添加</button>
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        {{ af.it_user|bootstrap_horizontal }}
                                        <div class="form-group" id="new_it_user" style="display:none">
                                            <label class="control-label col-sm-2 col-lg-2 red-fonts">新使用者</label>
                                            <div class=" col-sm-10 col-lg-10 ">
                                                <input class=" form-control" maxlength="32" name="new_it_user" type="text">
                                                <button type="button" class="col-sm-2 btn btn-info" id="new_field">添加</button>
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        {{ af.it_reason|bootstrap_horizontal }}
                                        <div class="hr-line-dashed"></div>
                                        {{ af.it_detail|bootstrap_horizontal }}
                                        <div class="hr-line-dashed"></div>
                                        {{ af.it_dec|bootstrap_horizontal }}
                                        <div class="hr-line-dashed"></div>

                                        {% comment %}

                                        <div class="form-group">
                                            <label class="control-label col-sm-2 col-lg-2 ">购买时间</label>
                                            <div class=" col-sm-10 col-lg-10 ">
                                                <input class=" form-control" id="id_it_buytime" maxlength="32" name="it_buytime" type="text" value="{{ it_buytime }}" >
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label class="control-label col-sm-2 col-lg-2 " for="id_it_usetime">使用时间</label>
                                            <div class=" col-sm-10 col-lg-10 ">
                                                <input class=" form-control" id="id_it_usetime" maxlength="32" name="it_usetime" type="text" value="{{ it_usetime }}">
                                            </div>
                                        </div>



                                        <div class="form-group">
                                            <label for="j_group" class="col-sm-2 control-label"></label>
                                            <div class="col-sm-2">
                                                <div class="radio i-checks">
                                                    <label>
                                                        <h4>
                                                            <input type="checkbox" checked="disabled" id="id_use_default_auth" name="use_default_auth"> 增加字段
                                                        </h4>
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                        {% endcomment %}

                                        <div class="form-group" id="admin_account" style="display: block">

                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_brand|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_size|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_channel|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_os|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_cpu|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_mem|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_ip|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_mac|bootstrap_horizontal }}
                                            <div class="hr-line-dashed"></div>
                                            {{ af.it_cost|bootstrap_horizontal }}
                                        </div>


                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <div class="col-sm-4 col-sm-offset-2">
                                                <button class="btn btn-white" type="reset"> 重置 </button>
                                                <button class="btn btn-primary" id="submit" type="submit"> 提交 </button>
                                            </div>
                                        </div>
                                </div>
                            </form>
                            <!-- xx -->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block self_footer_js %}
<script>
    $('document').ready(function(){
        // var remind = $("#id_it_serial").attr("value");
        console.log("#keyfield option[value='{{ keyfield }}']");
        console.log("1 + {{ keyword }}");
        $("#keyfield option[value='{{ keyfield }}']").attr("selected",true);
        $("#keyword").val("{{ keyword }}");
        //
        // $("#id_it_buytime").datetimepicker({
        //     format: 'yyyy-mm-dd',
        //     autoclose:true,
        //     minView:'year'});
        // $("#id_it_usetime").datetimepicker({
        //     format: 'yyyy-mm-dd',
        //     autoclose:true,
        //     minView:'year'});


        // init selected
        $("#id_it_status").val({{ it_status_index }});
        $("#id_it_type").val({{ it_type_index }});
        $("#id_it_dep").val({{ it_dep_index }});
        $("#id_it_user").val({{ it_user_index }});

        var check_default = 'default';
        $("#id_use_default_auth").removeAttr("checked");
        if (check_default != 'default'){
            $('#id_use_default_auth').attr('disabled', false);
            $('#id_use_default_auth').attr('checked', true);
            $('#admin_account').css('display', 'block');
        } else {
            $('#id_use_default_auth').click(function(){
                if ($(this).is(':checked')){
                    $('#admin_account').css('display', 'block');
                }
                else {
                    $('#admin_account').css('display', 'none');
                }
            })
        }

    });


    function display_add_block(tip_id){
            // var tip_id = $(this).attr('id');
            display_id ='new_' + tip_id.split("_").slice(0,2).join("_");
            console.log(display_id);
            // $('#' + display_id).css('display','block');
            //  $('#' + display_id).fadeToggle('slow');
             $('#' + display_id).slideToggle('slow');
    };
    $("#new_field").on("click",function(){
        var field_input = $(this).prev();
        var new_field_id = field_input.attr("name").split('_').slice(1,3).join('_');
        var field_value = field_input.val();
        var keyword = $(this).parent().prev().html();
        console.log('field_id: '+ new_field_id);
        console.log('field_value: '+ field_value);
        $.ajax({
            type: "post",
            url: "{% url 'asset_add_field' %}",
            data:{
                field_name : new_field_id,
                field_value: field_value,
                csrfmiddlewaretoken: "{{ csrf_token }}",
            },
            dataType:'json',
            beforeSend: function(XMLHttpRequest){
            //ShowLoading();
                console.log('beforeSend..');
            },
            success: function(data, textStatus){
                console.log('sucess.. ' + data);
                // alert(keyword + ' [' + field_value + '] 添加失败');
            },
            complete: function(XMLHttpRequest, textStatus){
            //HideLoading();
                console.log('finish request...');
                alert('操作完成！');
                parent.location.reload();
            },
            error: function(jqXHR, textStatus, errorThrown){
            //请求出错处理
                console.log('request error ');
                console.log(jqXHR.responseText);
                // alert(keyword + ' [' + field_value + '] 添加失败!\n是否已经存在？');
            }
        });
    });

</script>

{% endblock %}
</body>
</html>
